package com.zhj.designpatten;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

@Component
public class SmsListener implements SmartApplicationListener {
 
    /*@Override
    @Async
    public void onApplicationEvent(OrderCreateEvent event) {
        //发送短信
        System.out.println(event.getContentList().get(0) + ",您的订单:" + event.getContentList().get(1) + "创建成功! ----by sms");
 
    }*/

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return eventType==OrderCreateEvent.class;
    }

    @Override
    public boolean supportsSourceType(Class<?> sourceType) {
        return sourceType==OrderServiceImpl.class;
    }

    @Override
    public int getOrder() {
        return 4;
    }

    @Override
    @Async
    public void onApplicationEvent(ApplicationEvent event) {
        //发送短信
        if (event instanceof OrderCreateEvent){
            OrderCreateEvent event1=(OrderCreateEvent)event;
            System.out.println(event1.getContentList().get(0) + ",您的订单:" + event1.getContentList().get(0) + "创建成功! ----by sms");
        }

    }
}
